/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProfileJPanel.java
 *
 * Created on 4.2.2010, 23:13:44
 */

package jmenu.gui;

import java.awt.Cursor;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import jmenu.dbmodels.MProfile;
import jmenu.main.Config;
import jmenu.main.FitnessProgram;
import jmenu.main.Gender;


/**
 *
 * @author Boner
 */
public class ProfileJPanel extends javax.swing.JPanel {

    boolean enabled;

    /** Creates new form ProfileJPanel */
    public ProfileJPanel() {
        initComponents();
        init();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        loginLabel = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        weightLabel = new javax.swing.JLabel();
        heightLabel = new javax.swing.JLabel();
        weightstringLabel = new javax.swing.JLabel();
        hightstringLabel = new javax.swing.JLabel();
        surnameLabel = new javax.swing.JLabel();
        ageLabel = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        sexLabel = new javax.swing.JLabel();
        hRadioButton = new javax.swing.JRadioButton();
        nRadioButton = new javax.swing.JRadioButton();
        jLabel16 = new javax.swing.JLabel();
        agestringLabel = new javax.swing.JLabel();
        showGraphLabel = new javax.swing.JLabel();

        buttonGroup1.add(this.hRadioButton);
        buttonGroup1.add(this.nRadioButton);

        setBorder(javax.swing.BorderFactory.createTitledBorder("Profil"));
        setMaximumSize(new java.awt.Dimension(392, 150));
        setMinimumSize(new java.awt.Dimension(392, 150));
        setPreferredSize(new java.awt.Dimension(392, 150));
        setRequestFocusEnabled(false);

        jLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel.setText("login:");
        jLabel.setName("jLabel"); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("jméno:");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("příjmení:");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("váha:");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setText("výška:");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("věk:");
        jLabel5.setName("jLabel5"); // NOI18N

        loginLabel.setText("boner");
        loginLabel.setName("loginLabel"); // NOI18N

        nameLabel.setText("Roman");
        nameLabel.setName("nameLabel"); // NOI18N

        weightLabel.setText("85");
        weightLabel.setName("weightLabel"); // NOI18N

        heightLabel.setText("185");
        heightLabel.setName("heightLabel"); // NOI18N

        weightstringLabel.setText("kg");
        weightstringLabel.setName("weightstringLabel"); // NOI18N

        hightstringLabel.setText("cm");
        hightstringLabel.setName("hightstringLabel"); // NOI18N

        surnameLabel.setText("Oker");
        surnameLabel.setName("surnameLabel"); // NOI18N

        ageLabel.setText("100");
        ageLabel.setName("ageLabel"); // NOI18N

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel14.setText("pohlaví:");
        jLabel14.setName("jLabel14"); // NOI18N

        sexLabel.setText("muž");
        sexLabel.setName("sexLabel"); // NOI18N

        hRadioButton.setText("hubnutí");
        hRadioButton.setName("hRadioButton"); // NOI18N
        hRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hRadioButtonActionPerformed(evt);
            }
        });

        nRadioButton.setText("nabírání");
        nRadioButton.setName("nRadioButton"); // NOI18N
        nRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nRadioButtonActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel16.setText("režim:");
        jLabel16.setName("jLabel16"); // NOI18N

        agestringLabel.setText("let");
        agestringLabel.setName("agestringLabel"); // NOI18N

        showGraphLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/diagram-16.png"))); // NOI18N
        showGraphLabel.setToolTipText("Zobrazit graf");
        showGraphLabel.setName("showGraphLabel"); // NOI18N
        showGraphLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                showGraphLabelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(8, 8, 8)
                            .addComponent(jLabel4))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(5, 5, 5)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel)
                                .addComponent(jLabel1))))
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(heightLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(hightstringLabel)
                        .addGap(52, 52, 52))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(loginLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                            .addComponent(nameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(weightLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(weightstringLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(showGraphLabel)
                                .addGap(22, 22, 22))
                            .addComponent(sexLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel16)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(surnameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ageLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(agestringLabel))
                    .addComponent(hRadioButton)
                    .addComponent(nRadioButton))
                .addGap(73, 73, 73))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel)
                    .addComponent(loginLabel)
                    .addComponent(jLabel5)
                    .addComponent(ageLabel)
                    .addComponent(agestringLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(nameLabel)
                    .addComponent(surnameLabel))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(hRadioButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(sexLabel))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(weightLabel)
                            .addComponent(weightstringLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(heightLabel)
                            .addComponent(hightstringLabel)))
                    .addComponent(nRadioButton)
                    .addComponent(showGraphLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void hRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hRadioButtonActionPerformed
        Config.getSettings().setProgram(FitnessProgram.SLIMMING);
        Config.getMainFrame().updateFitnessProgram();
    }//GEN-LAST:event_hRadioButtonActionPerformed

    private void nRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nRadioButtonActionPerformed
       Config.getSettings().setProgram(FitnessProgram.BOOSTING);
       Config.getMainFrame().updateFitnessProgram();
    }//GEN-LAST:event_nRadioButtonActionPerformed

    private void showGraphLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showGraphLabelMouseClicked
        ShowWeightGraphDialog graph = new ShowWeightGraphDialog(Config.getMainFrame(), true);
    }//GEN-LAST:event_showGraphLabelMouseClicked

    public void init()
    {
        this.enabled = false;
        this.loginLabel.setText("");
        this.nameLabel.setText("");
        this.surnameLabel.setText("");
        this.weightLabel.setText("");
        this.heightLabel.setText("");
        this.sexLabel.setText("");
        this.ageLabel.setText("");
        this.agestringLabel.setVisible(false);
        this.weightstringLabel.setVisible(false);
        this.hightstringLabel.setVisible(false);
        this.buttonGroup1.clearSelection();


        this.showGraphLabel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        this.showGraphLabel.setEnabled(false);

    }

    public void enableProfilePanel()
    {
        this.enabled = true;

        this.hRadioButton.setEnabled(true);
        this.nRadioButton.setEnabled(true);

        this.showGraphLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
         this.showGraphLabel.setEnabled(true);
    }

    public void disableProfilePanel()
    {
        this.init();
        this.hRadioButton.setEnabled(false);
        this.nRadioButton.setEnabled(false);
    }


    public void setProfile(MProfile profile)
    {

        this.loginLabel.setText(profile.getLogin());
        this.nameLabel.setText(profile.getName());
        this.surnameLabel.setText(profile.getSurname());
        this.weightLabel.setText(String.valueOf(profile.getWeight()));
        this.heightLabel.setText(String.valueOf(profile.getHeight()));

        if (profile.getSex() == Gender.MAN)
            this.sexLabel.setText("muž");
        else if (profile.getSex() == Gender.WOMAN)
            this.sexLabel.setText("žena");

        Calendar cal = new GregorianCalendar(TimeZone.getDefault());
    
        int now = cal.get(Calendar.YEAR);
        cal.setTime(profile.getAge());
        cal.get(Calendar.YEAR);
    
        this.ageLabel.setText(String.valueOf(now - cal.get(Calendar.YEAR)));

        if (Config.getSettings().getProgram() == FitnessProgram.SLIMMING)
            this.buttonGroup1.setSelected(hRadioButton.getModel(), true);
        else if (Config.getSettings().getProgram() == FitnessProgram.BOOSTING)
            this.buttonGroup1.setSelected(nRadioButton.getModel(), true);

        this.agestringLabel.setVisible(true);
        this.weightstringLabel.setVisible(true);
        this.hightstringLabel.setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ageLabel;
    private javax.swing.JLabel agestringLabel;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JRadioButton hRadioButton;
    private javax.swing.JLabel heightLabel;
    private javax.swing.JLabel hightstringLabel;
    private javax.swing.JLabel jLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel loginLabel;
    private javax.swing.JRadioButton nRadioButton;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JLabel sexLabel;
    private javax.swing.JLabel showGraphLabel;
    private javax.swing.JLabel surnameLabel;
    private javax.swing.JLabel weightLabel;
    private javax.swing.JLabel weightstringLabel;
    // End of variables declaration//GEN-END:variables

}
